import getvalue2
import  wxchat;
import tkinter as tk
import argparse
from PIL import Image
import time
import os
from datetime import datetime
import uuid
import addnodetofile



def generate_random_id():
    # 生成一个 UUID
    random_uuid = uuid.uuid4()
    # 将 UUID 转换为十六进制字符串并取前 16 位
    return random_uuid.hex[:16]


parser = argparse.ArgumentParser(description='处理图片及相关信息的脚本')
parser.add_argument('-imagepath', type=str, required=True, help='图片的路径')
parser.add_argument('-msg', type=str, required=True, help='用户的输入信息')

args = parser.parse_args()
image_path = args.imagepath
user_msg = args.msg


def show_notification():
    root = tk.Tk()
    root.overrideredirect(True)  # 去除窗口边框和标题栏

    # 设置窗口位置
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    x = screen_width // 2 - 100
    y = screen_height // 2 - 50
    root.geometry(f"200x100+{x}+{y}")

    label = tk.Label(root, text="这是一个桌面提示！", font=("Arial", 12))
    label.pack(pady=20)

    root.after(3000, root.destroy)  # 3秒后自动关闭窗口
    root.mainloop()

# 笔记文件夹
wikipath="E:\\wiki\\wikiob\\a2\\全新"

dic={
    'beforewidth':0,
    "beforeinput":"",
    "windowroot":None
    }

save_folder = f"{wikipath}\\_files"
if not os.path.exists(save_folder):
    os.makedirs(save_folder)

##.py

print('image_path===>',image_path)
img = Image.open(image_path)
getvalue2.setvalue2txt(user_msg)


# 发送钉钉
wxchat.sendImage2dingding(img,user_msg)
# 发送到文档笔记
print('------------发送到文档笔记-----------------')
list1 = user_msg.split('#')
list2 = [s for s in list1 if s.strip()]
firsttag = list2[0]
# 获取第一个 然后附件名称.canvas保存起来
file_name = str(int(time.time())) + ".png"
file_path = os.path.join(save_folder, file_name)
img.save(file_path)
print(f"已成功将图片保存到 {file_path}")

tagstr = f"{user_msg}#{datetime.now().strftime('%Y年%m月%d日')}"
markdown=f"{tagstr}\n![[_files/{file_name}]]\n\n\n"
_dic = {
    "id": generate_random_id(),
    "type": "text",
    "text": markdown,
    "styleAttributes": {},
    "x": -220,
    "y": 140,
    "width": img.width,
    "height": img.height
}
print("_dic", _dic);

getvalue2.setvalue2txt('markdown',r'E:\home\blog\pycut2\Image-recognition-enters-the-whiteboard\_setuserinputandimg.txt')
addnodetofile.add_node_to_file(_dic, f"{firsttag}.canvas", wikipath)


